package com.xci.core.setting;

import com.xci.core.helper.Helper;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

/**
 * 上传配置参数
 *
 * @author 吕艳阳
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "xci.upload")
public class UploadSetting {
    /**
     * 上传根目录
     */
    private String root = "/data";

    /**
     * 允许上传的扩展名,不含点
     */
    private String[] allowExtension = new String[]{"gif", "jpg", "jpeg", "png", "bmp", "flv", "mp3", "mp4", "wav", "wma", "avi", "mpg", "rmvb", "zip", "rar", "doc", "docx", "xls", "xlsx", "ppt", "pptx", "txt", "pdf"};

    /**
     * 允许上传的最大文件大小,单位KB
     */
    private long allowMaxSize = 10240;

    /**
     * 上传更新包密码
     */
    private String upgradePassword="www.xci.96716.com";

    /**
     * 生成上传文件相对路径
     *
     * @param path 路径
     */
    public String buildPath(String path) {
        if (Helper.isBlank(root)) {
            root = "/data";
        }
        if (!root.startsWith("/")) {
            root = "/" + root;
        }
        if (root.endsWith("/")) {
            root = root.substring(0, root.length() - 1);
        }
        if (!path.startsWith("/")) {
            path = "/" + path;
        }
        return root + path;
    }
}